//
//  HWLiBaoView.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/9/5.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWLiBaoView.h"
#import "UIButton+AFNetworking.h"

@interface HWLiBaoView()
@property(strong,nonatomic) NSArray *listArr;
@property(strong,nonatomic) NSArray *icoArr;
//@property(strong,nonatomic) NSMutableArray *buttMuArr;
@property(strong,nonatomic) NSMutableArray *imageViewMuArr;
@property(strong,nonatomic) NSMutableArray *labeMuArr;


@end

@implementation HWLiBaoView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self setUpUI];
    }
    
    return  self;
}



#pragma  msrk  ------   设置UI
- (void)setUpUI {
    
    
    self.listArr = @[@"我的礼包",@"我的关注",@"我的收藏",@"我的账单",@" 我的绑币",@"小号管理",@"设置中心",@"账户安全"];
    self.icoArr = @[@"person_gift",@"personal_like",@"personal_collerct",@"personal_bill",@"personal_b_bangding",@"personal__num",@"personal_set",@"personal_safe"];
    
//     self.icoArr = @[@"person_g1ift",@"perso1nal_like",@"personal1_collerct",@"p1erso1nal_bill",@"person1al1_b_bangding",@"persona1l1__num",@"pe1rsonal_s1et",@"personal1_safe"];
    
    self.imageViewMuArr = [[NSMutableArray alloc]init];
    self.labeMuArr = [[NSMutableArray alloc]init];
    
    
    CGFloat hengjianju = (kScreenW - 30-4*54)/8;
    CGFloat  shujianju = (166-100)/3;
    
    for (int i = 0 ; i < self.listArr.count; i++) {
        int row = i/4;
        int line = i%4;


        UIView *beijingview = [[UIView alloc]initWithFrame:CGRectMake(line*54+hengjianju*(line*2+1), shujianju*row+shujianju+row*50, 50+4, 50)];
      //  beijingview.backgroundColor = [UIColor redColor];
        [self addSubview:beijingview];
        
        beijingview.tag = i;
        UITapGestureRecognizer *beijingGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(beijingTap:)];
        [beijingview addGestureRecognizer:beijingGesture];
        
        
        
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((54-22.5)/2, 0, 22.5, 22)];
       // imageView.image = [UIImage imageNamed:self.icoArr[i]];
     //   imageView.userInteractionEnabled = YES;
        [beijingview addSubview:imageView];
        imageView.tag = i;
        [self.imageViewMuArr addObject:imageView];
        
        
        UITapGestureRecognizer *tap  = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(iamgetap:)];
        [imageView addGestureRecognizer:tap];
        
        
        
        UILabel *shulianlabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 30, 54, 20)];
        shulianlabel.textColor =RGB(51, 51, 51);
      //  shulianlabel.text = self.listArr[i];
             //  shulianlabel.backgroundColor = [UIColor orangeColor];
        shulianlabel.font = [UIFont systemFontOfSize:12];
        shulianlabel.textAlignment = NSTextAlignmentCenter;
        [beijingview addSubview:shulianlabel];
        [self.labeMuArr addObject:shulianlabel];
        
        
        
        

        
        
    
    }
    
    
}

- (void)buttonTap:(UIButton *)sende {
    
    [self.delegate xuanzhongTap:sende.tag];

    
}





- (void)iamgetap:(UITapGestureRecognizer *)sender {
    
       //  sender.view  这个没有用上
      UIImageView *imageView = (UIImageView *)sender.view;
      NSInteger tag = imageView.tag;
      NSDictionary *dic =self.dataArr[tag];
      [self.delegate xuanzhongDic:dic];
    
    
    
}


- (void)beijingTap:(UITapGestureRecognizer *)sender {
    
    UIView *imageView = (UIView *)sender.view;
    NSInteger tag = imageView.tag;
    NSDictionary *dic =self.dataArr[tag];
    [self.delegate xuanzhongDic:dic];
    
    
    
}





-(void)setDataArr:(NSArray *)dataArr {
    
    _dataArr = dataArr;
    
    
    NSLog(@"熟练 %ld",dataArr.count);
    
    for (int i = 0 ; i < dataArr.count; i++) {
        
//        UIButton *but = (UIButton *)self.buttMuArr[i];
//        but.hidden = NO;
//
        NSDictionary *dic = dataArr[i];
        
        UIImageView *imageView = self.imageViewMuArr[i];
        UILabel *label = self.labeMuArr[i];
        
        [imageView sd_setImageWithURL:[NSURL URLWithString:dic[@"icon"]] placeholderImage:nil];
        label.text   = [NSString stringWithFormat:@"%@",dic[@"name"]];
    
        
    }
    
    
    
}





@end
